<style>
td {
	border: solid #68BADA;
	border-width: 0px 1px 1px 0px;
	padding: 5px;
	text-align: center
}
table {
	border: solid #68BADA;
	border-width: 1px 0px 0px 1px;
}
.odd {
	background: none repeat scroll 0 0 #EEEEEE;
}
.even {
	background: none repeat scroll 0 0 #FFFFFF;
}
.three {
	background: none repeat scroll 0 0 #E5F1F4;
}
.jg {
	background: none repeat scroll 0 0 #ADD9ED;
}
.head {
	background: none repeat scroll 0 0 #90D8F0;
}
input, img {
	vertical-align: middle;
}
</style>
<script>
function recommend(activityid,status,actname){
	var info;
	if(status==0){
		info = '確認要推薦：'+actname;
	}else{
		info = '確認要取消推薦：'+actname;
	}
	
	if(!confirm(info)){
		return false;
	}
	$.post('<?php echo CHtml::normalizeUrl(array('/activity/recommend'));?>',{'id':activityid}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
			alert(ret.msg);
			location.reload(true);
        }
	});	
}
function publish(activityid,actname){
	if(!confirm('確認要開獎：'+actname)){
		return false;
	}
	$.post('<?php echo CHtml::normalizeUrl(array('/activity/publish'));?>',{'id':activityid}, function (data) {
        var ret = $.parseJSON(data);
        if (ret != null && ret.success != null && ret.success) {
			alert(ret.msg);
			location.reload(true);
        }
	});	
}
</script>
<?php
$this->breadcrumbs=array(
	'活動管理'=>array('index'),
	'活動列表',
);
?>
<div style="width:10%; float:left; text-align:left;">
<a href="<?=Yii::app()->createUrl('activity/create')?>">新增活動</a>
</div>
<div style="width:90%; float:left; margin-bottom:10px; text-align:right;">
	<form action="<?=Yii::app()->createUrl('activity/index')?>" name="jobForm" id="jobForm" method="get">
		<?php echo CHtml::dropDownList('class',$search['class'], Yii::app()->params['activityclasses']);?>	
		<?php echo CHtml::dropDownList('status',$search['status'], Yii::app()->params['activitystatus']);?>
		<?php echo CHtml::dropDownList('timetype',$search['timetype'], Yii::app()->params['activitytimetype']);?>： <input type="text" name="s" id="s" value="<?= $search['s'] ?>" readonly="readonly" style="width:88px;" />
		<img onclick="displayCalendar(document.jobForm.s,'yyyy-mm-dd',this)" style="cursor:pointer;" src="images/calendar.png" /> - 
		<input type="text" name="e" id="e" value="<?= $search['e'] ?>" readonly="readonly" style="width:88px;" />
		<img onclick="displayCalendar(document.jobForm.e,'yyyy-mm-dd',this)" style="cursor:pointer;" src="images/calendar.png" />
		<?php echo CHtml::dropDownList('searchtype',$search['searchtype'], Yii::app()->params['activitysearchtype']);?>
		： <input type="text" name="key" value="<?php if(isset($search['key']))echo $search['key'];?>" id="oid" size="10" />
		<input type="image" src="images/go.png" id="jobSub" />
		<input type="hidden" name="r" value="activity/index" />
	</form>
</div>
<table cellspacing="0" cellpadding="0" width="100%" class="tbl">
	<tr class="head">
		<td width="2%">ID</td>
		<td width="10%">活動ID</td>
		<td width="27%">活動名稱</td>
		<td width="7%">活動分類</td>
		<td width="15%">開始時間</td>
		<td width="6%">推薦</td>
		<td width="7%">狀態</td>
		<td width="10%">創建時間</td>
		<td width="5%">開獎</td>
		<td>操作</td>
	</tr>
	<?php
    $i = 0;
    $cssArr = array(0 => 'even', 1 => 'odd', 2 => 'three');
    foreach ($rowTable as $item) {
        $trClass = $cssArr[$i % 3];
        $i++;
    ?>
	<tr class="<?= $trClass ?>">
		<td>
			<?=$i?>
		</td>
		<td>
			<?=$item->serial?>
		</td>
		<td>
			<?=$item->activityname?>
		</td>
		<td>
			<?=$item->class?>
		</td>
		<td>
			<?=$item->starttime?>
		</td>
		<td>
			<?=Yii::app()->params['activityrecommend'][$item->recommend]?>
		</td>
		<td>
			<?=Yii::app()->params['activitystatus'][$item->status]?>
		</td>
		<td>
			<?=date('Y-m-d',strtotime($item['dateline']))?>
		</td>
		<td>
		<?php
		if($item->status==3){
		?>
		<a href="###" onclick="publish(<?=$item->activityid?>,'<?=$item->activityname?>');">開獎</a>
		<?
		}
		?>			
		</td>
		<td>
			<a title='瀏覽' href="<?=Yii::app()->createUrl('activity/view',array('id'=>$item->activityid))?>"><img alt="瀏覽" src="/admin/images/zoomin.png"></a>
			<a title="編輯" href="<?=Yii::app()->createUrl('activity/update',array('id'=>$item->activityid))?>"><img alt="編輯" src="/admin/images/edit.png"></a>
			<a title="推薦" onclick="recommend(<?=$item->activityid?>,<?=$item->recommend?>,'<?=$item->activityname?>')" href="###"><img alt="推薦" src="/admin/images/heart.png"></a>
			<a title="刪除" onclick="return confirm('確定要刪除?')" href="<?=Yii::app()->createUrl('activity/Delete',array('id'=>$item->activityid))?>"><img alt="刪除" src="/admin/images/trash.png"></a>
		</td>
	</tr>
	<?php
    }
    ?>
</table>
<div id="pager" align="center">
	<?php  
	$this->widget('CLinkPager',array(  
		'header'=>'',  
		'firstPageLabel' => '<<',
		'lastPageLabel' => '>>',
		'prevPageLabel' => '<',
		'nextPageLabel' => '>',
		'pages' => $pages,  
		'maxButtonCount'=>13  
		));  
?>
</div>
